package GUI窗体和Swing.事件处理机制.Swing常用事件处理;
//键盘事件处理
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;

public class text3 {
    public static void main(String[] args) {
        JFrame jf = new JFrame();
        jf.setTitle("键盘事件处理");
        jf.setBounds(100,100,400,300);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
        JTextArea jta = new JTextArea();
        jf.add(jta);
        JButton jb = new JButton("登录");
        jf.add(jb);
        jb.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                int c = e.getKeyCode();
                if(c == 10){
                    System.out.println("登录成功");
                }
            }
        });
    }
}
